#include <stdint.h>
#include <stdbool.h>

#include <colorFormula.h>

#define U16_MAX   65535u


//OSRAM LRTBGVSG
const Coordinate_t TABLE_BIN_XY_RED[][4] = 
{
    //2
    (uint16_t)(0.6880*U16_MAX), (uint16_t)(0.3085*U16_MAX),
    (uint16_t)(0.6915*U16_MAX), (uint16_t)(0.3083*U16_MAX),
    (uint16_t)(0.7006*U16_MAX), (uint16_t)(0.2993*U16_MAX),
    (uint16_t)(0.6969*U16_MAX), (uint16_t)(0.2997*U16_MAX),
    //3
    (uint16_t)(0.6936*U16_MAX), (uint16_t)(0.3030*U16_MAX),
    (uint16_t)(0.6972*U16_MAX), (uint16_t)(0.3027*U16_MAX),
    (uint16_t)(0.7065*U16_MAX), (uint16_t)(0.2934*U16_MAX),
    (uint16_t)(0.7028*U16_MAX), (uint16_t)(0.2938*U16_MAX),
    //4
    (uint16_t)(0.7000*U16_MAX), (uint16_t)(0.2966*U16_MAX),
    (uint16_t)(0.7037*U16_MAX), (uint16_t)(0.2962*U16_MAX),
    (uint16_t)(0.7104*U16_MAX), (uint16_t)(0.2895*U16_MAX),
    (uint16_t)(0.7068*U16_MAX), (uint16_t)(0.2899*U16_MAX),
};


const Coordinate_t TABLE_BIN_XY_GREEN[][4] = 
{
    //2
    (uint16_t)(0.1507*U16_MAX), (uint16_t)(0.6751*U16_MAX),
    (uint16_t)(0.1150*U16_MAX), (uint16_t)(0.7420*U16_MAX),
    (uint16_t)(0.1367*U16_MAX), (uint16_t)(0.7504*U16_MAX),
    (uint16_t)(0.1661*U16_MAX), (uint16_t)(0.6927*U16_MAX),
    //3
    (uint16_t)(0.1592*U16_MAX), (uint16_t)(0.6856*U16_MAX),
    (uint16_t)(0.1295*U16_MAX), (uint16_t)(0.7456*U16_MAX),
    (uint16_t)(0.1517*U16_MAX), (uint16_t)(0.7547*U16_MAX),
    (uint16_t)(0.1753*U16_MAX), (uint16_t)(0.6999*U16_MAX),
    //4
    (uint16_t)(0.1681*U16_MAX), (uint16_t)(0.6938*U16_MAX),
    (uint16_t)(0.1415*U16_MAX), (uint16_t)(0.7518*U16_MAX),
    (uint16_t)(0.1652*U16_MAX), (uint16_t)(0.7560*U16_MAX),
    (uint16_t)(0.1854*U16_MAX), (uint16_t)(0.7052*U16_MAX),
    //5
    (uint16_t)(0.1773*U16_MAX), (uint16_t)(0.7009*U16_MAX),
    (uint16_t)(0.1543*U16_MAX), (uint16_t)(0.7551*U16_MAX),
    (uint16_t)(0.1795*U16_MAX), (uint16_t)(0.7549*U16_MAX),
    (uint16_t)(0.1961*U16_MAX), (uint16_t)(0.7091*U16_MAX),
    //6
    (uint16_t)(0.1875*U16_MAX), (uint16_t)(0.7064*U16_MAX),
    (uint16_t)(0.1678*U16_MAX), (uint16_t)(0.7565*U16_MAX),
    (uint16_t)(0.1944*U16_MAX), (uint16_t)(0.7509*U16_MAX),
    (uint16_t)(0.2079*U16_MAX), (uint16_t)(0.7099*U16_MAX),
    //7
    (uint16_t)(0.1983*U16_MAX), (uint16_t)(0.7096*U16_MAX),
    (uint16_t)(0.1824*U16_MAX), (uint16_t)(0.7542*U16_MAX),
    (uint16_t)(0.2098*U16_MAX), (uint16_t)(0.7449*U16_MAX),
    (uint16_t)(0.2203*U16_MAX), (uint16_t)(0.7099*U16_MAX),
    //8
    (uint16_t)(0.2103*U16_MAX), (uint16_t)(0.7105*U16_MAX),
    (uint16_t)(0.1974*U16_MAX), (uint16_t)(0.7500*U16_MAX),
    (uint16_t)(0.2419*U16_MAX), (uint16_t)(0.7273*U16_MAX),
    (uint16_t)(0.2474*U16_MAX), (uint16_t)(0.7029*U16_MAX),
    //9
    (uint16_t)(0.2363*U16_MAX), (uint16_t)(0.7063*U16_MAX),
    (uint16_t)(0.2288*U16_MAX), (uint16_t)(0.7353*U16_MAX),
    (uint16_t)(0.2751*U16_MAX), (uint16_t)(0.7042*U16_MAX),
    (uint16_t)(0.2777*U16_MAX), (uint16_t)(0.6880*U16_MAX),
};


const Coordinate_t TABLE_BIN_XY_BLUE[][4] = 
{
    //H 0
    (uint16_t)(0.1622*U16_MAX), (uint16_t)(0.0203*U16_MAX),
    (uint16_t)(0.1595*U16_MAX), (uint16_t)(0.0152*U16_MAX),
    (uint16_t)(0.1556*U16_MAX), (uint16_t)(0.0186*U16_MAX),
    (uint16_t)(0.1588*U16_MAX), (uint16_t)(0.0243*U16_MAX),
    //I 1
    (uint16_t)(0.1606*U16_MAX), (uint16_t)(0.0222*U16_MAX),
    (uint16_t)(0.1576*U16_MAX), (uint16_t)(0.0168*U16_MAX),
    (uint16_t)(0.1534*U16_MAX), (uint16_t)(0.0206*U16_MAX),
    (uint16_t)(0.1570*U16_MAX), (uint16_t)(0.0268*U16_MAX),
    //J 2
    (uint16_t)(0.1588*U16_MAX), (uint16_t)(0.0243*U16_MAX),
    (uint16_t)(0.1556*U16_MAX), (uint16_t)(0.0186*U16_MAX),
    (uint16_t)(0.1500*U16_MAX), (uint16_t)(0.0246*U16_MAX),
    (uint16_t)(0.1543*U16_MAX), (uint16_t)(0.0317*U16_MAX),
    //K 3
    (uint16_t)(0.1562*U16_MAX), (uint16_t)(0.0285*U16_MAX),
    (uint16_t)(0.1524*U16_MAX), (uint16_t)(0.0219*U16_MAX),
    (uint16_t)(0.1462*U16_MAX), (uint16_t)(0.0293*U16_MAX),//?
    (uint16_t)(0.1509*U16_MAX), (uint16_t)(0.0370*U16_MAX),
    //L 4
    (uint16_t)(0.1532*U16_MAX), (uint16_t)(0.0332*U16_MAX),
    (uint16_t)(0.1489*U16_MAX), (uint16_t)(0.0262*U16_MAX),
    (uint16_t)(0.1436*U16_MAX), (uint16_t)(0.0332*U16_MAX),
    (uint16_t)(0.1487*U16_MAX), (uint16_t)(0.0414*U16_MAX),
    //M 5
    (uint16_t)(0.1509*U16_MAX), (uint16_t)(0.0370*U16_MAX),
    (uint16_t)(0.1462*U16_MAX), (uint16_t)(0.0293*U16_MAX),
    (uint16_t)(0.1407*U16_MAX), (uint16_t)(0.0376*U16_MAX),
    (uint16_t)(0.1463*U16_MAX), (uint16_t)(0.0463*U16_MAX),
    
    //N 6
    (uint16_t)(0.1487*U16_MAX), (uint16_t)(0.0414*U16_MAX),
    (uint16_t)(0.1436*U16_MAX), (uint16_t)(0.0332*U16_MAX),
    (uint16_t)(0.1375*U16_MAX), (uint16_t)(0.0428*U16_MAX),
    (uint16_t)(0.1436*U16_MAX), (uint16_t)(0.0519*U16_MAX),
    //O 7
    (uint16_t)(0.1463*U16_MAX), (uint16_t)(0.0463*U16_MAX),
    (uint16_t)(0.1407*U16_MAX), (uint16_t)(0.0376*U16_MAX),
    (uint16_t)(0.1338*U16_MAX), (uint16_t)(0.0493*U16_MAX),
    (uint16_t)(0.1404*U16_MAX), (uint16_t)(0.0588*U16_MAX),
    //P 8
    (uint16_t)(0.1436*U16_MAX), (uint16_t)(0.0519*U16_MAX),
    (uint16_t)(0.1375*U16_MAX), (uint16_t)(0.0428*U16_MAX),
    (uint16_t)(0.1272*U16_MAX), (uint16_t)(0.0620*U16_MAX),
    (uint16_t)(0.1354*U16_MAX), (uint16_t)(0.0727*U16_MAX),
    
    //Q 9
    (uint16_t)(0.1389*U16_MAX), (uint16_t)(0.0631*U16_MAX),
    (uint16_t)(0.1317*U16_MAX), (uint16_t)(0.0532*U16_MAX),
    (uint16_t)(0.1199*U16_MAX), (uint16_t)(0.0785*U16_MAX),
    (uint16_t)(0.1295*U16_MAX), (uint16_t)(0.0899*U16_MAX),
    //R 10
    (uint16_t)(0.1335*U16_MAX), (uint16_t)(0.0779*U16_MAX),
    (uint16_t)(0.1251*U16_MAX), (uint16_t)(0.0672*U16_MAX),
    (uint16_t)(0.1115*U16_MAX), (uint16_t)(0.1000*U16_MAX),
    (uint16_t)(0.1231*U16_MAX), (uint16_t)(0.1122*U16_MAX),
    
};


const uint16_t TABLE_BIN_LUMEN_RED[]=
{
    (500 + 630)/2,//UE
    (529 + 669)/2,//UF
    (560 + 710)/2,//UG
    (594 + 754)/2,//UH
    (630 + 800)/2,//UI
    (669 + 849)/2,//UJ
    (710 + 900)/2,//VC
    (754 + 949)/2,//VD
    (800 +1000)/2,//VE
};

const uint16_t TABLE_BIN_LUMEN_GREEN[]=
{
    (1250 + 1590)/2,//AM
    (1323 + 1692)/2,//AN
    (1400 + 1800)/2,//AO
    (1492 + 1902)/2,//AP
    (1590 + 2010)/2,//AQ
};


const uint16_t TABLE_BIN_LUMEN_BLUE[]=
{
    (180 + 224)/2,//SC
    (190 + 237)/2,//SD
    (201 + 250)/2,//SE
    (212 + 265)/2,//SF
    (224 + 280)/2,//SG
    (237 + 287)/2,//SH
    (250 + 315)/2,//SI
    (265 + 334)/2,//SJ
    (280 + 355)/2,//TC
    (297 + 377)/2,//TD
    (315 + 400)/2,//TE
    (334 + 424)/2,//TF
    (355 + 450)/2,//TG
    (377 + 474)/2,//TH
    (400 + 500)/2,//TI
    (424 + 529)/2,//TJ
    (450 + 560)/2,//UC
};


const TempCompensation_t TABLE_CMP_INTENSITY_RED[] = 
{
    //T(0.1C)   deltaV(mV) efficiency(0.1%)
    -400, 208,  142,
    -300, 170,  135,
    -200, 123,  129,
    -100, 88,   122,
    0,    59,   116,
    100,  35,   110,
    200,  15,   104,
    250,  0,    100,
    300,  -15,  97,
    400,  -25,  90,
    500,  -46,  83,
    600,  -60,  76,
    700,  -80,  70,
    800,  -90,  62,
    900,  -110, 56,
    1000, -119, 49,
};

const TempCompensation_t TABLE_CMP_INTENSITY_GREEN[] = 
{
    -400, 350,  101,
    -300, 280,  102,
    -200, 220,  102,
    -100, 166,  102,
    0,    120,  101,
    100,  70,   101,
    200,  10,   100,
    250,  0,    100,
    300,  -30,  99,
    400,  -80,  98,
    500,  -128, 97,
    600,  -160, 95,
    700,  -210, 94,
    800,  -240, 92,
    900,  -280, 91,
    1000, -320, 89,
};

const TempCompensation_t TABLE_CMP_INTENSITY_BLUE[] = 
{
    -400, 190,  97,
    -300, 160,  97,
    -200, 114,  97,
    -100, 83,   98,
    0,    57,   98,
    100,  40,   99,
    200,  15,   100,
    250,  0,    100,
    300,  -10,  101,
    400,  -30,  102,
    500,  -49,  104,
    600,  -60,  105,
    700,  -90,  107,
    800,  -110, 108,
    900,  -130, 110,
    1000, -150, 111,
};


















